package com.atguigu.tingshu.order.api;

import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.order.OrderInfo;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import com.atguigu.tingshu.vo.order.TradeVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "订单管理")
@RestController
@RequestMapping("api/order")
@SuppressWarnings({"all"})
public class OrderInfoApiController {

	@Autowired
	private OrderInfoService orderInfoService;





	// /api/order/orderInfo/getOrderInfo/202401171747525451439460352 get
	@GetMapping("/orderInfo/getOrderInfo/{orderNo}")
	public Result<OrderInfo> getOrderInfo(@PathVariable("orderNo") String orderNo){
		OrderInfo orderInfo =orderInfoService.getOrderInfo(orderNo);
		return Result.ok(orderInfo);
	}
	///api/order/orderInfo/findUserPage/1/10 get
	@GetMapping("/orderInfo/findUserPage/{pageNo}/{limit}")
	@GuiGuLogin
	public Result<Page<OrderInfo>> findUserPage(@PathVariable("pageNo") Long pageNo, @PathVariable("limit") Long limit){
		Page<OrderInfo> page = new Page<>(pageNo,limit);
		page = orderInfoService.findUserPage(page);
		return Result.ok(page);
	}

	///api/order/orderInfo/submitOrder post
	@PostMapping("/orderInfo/submitOrder")
	@GuiGuLogin
	public Result<Map<String, String>> submitOrder(@RequestBody OrderInfoVo orderInfoVo){
		Map<String, String> ordero =  orderInfoService.submitOrder(orderInfoVo);
		return Result.ok(ordero);
	}
	@PutMapping("/orderInfo/orderPaySuccess/{orderNo}")
	public Result orderPaySuccess(@PathVariable String orderNo){
		orderInfoService.orderPaySuccess(orderNo);
		return Result.ok();
	}

	/**
	 * 订单结算页面数据汇总（VIP会员、专辑、声音）
	 *
	 * @param tradeVo
	 * @return 订单信息VO对象
	 */
	@GuiGuLogin
	@Operation(summary = "订单结算页面数据汇总（VIP会员、专辑、声音）")
	@PostMapping("/orderInfo/trade")
	public Result<OrderInfoVo> tradeOrderData(@RequestBody TradeVo tradeVo) {
		Long userId = AuthContextHolder.getUserId();
		OrderInfoVo orderInfoVo = orderInfoService.tradeOrderData(userId, tradeVo);
		return Result.ok(orderInfoVo);
	}
}

